package com.ftg.learn.util;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
@Schema(name = "返回结果")
public class R<T> {
    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "返回信息")
    private String msg;
    @Schema(description = "返回数据")
    private T data;

    public static <T> R<T> success(T data) {
        return new R<>(RMessCommEnum.R_MESS_COMM_ENUM_SUCCESS.getCode(),  RMessCommEnum.R_MESS_COMM_ENUM_SUCCESS.getMsg(), data);
    }

    public static <T> R<T> error(String msg) {
        return new R<>(RMessCommEnum.R_MESS_COMM_ENUM_FAIL.getCode(), msg, null);
    }

    public static <T> R<T> build(RMessCommEnum r){
        return new R<>(r.getCode(), r.getMsg(), null);
    }

    public static <T>  R<T> build(RMessCommEnum r, T data){
        return new R<>(r.getCode(), r.getMsg(), data);
    }

}
